package com.tx.admin.util.common;

import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;

public class StringUtil {

	private static final  VelocityEngine ve;

	static {
	    ve = new VelocityEngine();
		ve.init();
	}
	
	public static String render(String text,Map<String,Object> params) {
	    	VelocityContext context = new VelocityContext();
	    	for(Entry<String, Object> e: params.entrySet()) {
	    		context.put(e.getKey(), e.getValue());
	    	}
	    	StringWriter writer = new StringWriter();
	    	ve.evaluate(context, writer, "", text); // 关键方法
	    	return writer.toString();
	}
	
	//首字母转小写
	public static String toLowerCaseFirstOne(String s){
	  if(Character.isLowerCase(s.charAt(0)))
	    return s;
	  else
	    return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
	}


	//首字母转大写
	public static String toUpperCaseFirstOne(String s){
	  if(Character.isUpperCase(s.charAt(0)))
	    return s;
	  else
	    return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
	}
		
}
